//
//  CommunityTableViewCell.m
//  shusheng
//
//  Created by rimi on 16/7/15.
//  Copyright © 2016年 yuying. All rights reserved.
//

#import "CommunityTableViewCell.h"
//#import "UIView+SDAutoLayout.h"
#import "SDAutoLayout.h"

@implementation CommunityTableViewCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = RGBCOLOR(229, 229, 229);
        [self initializeUserInterface];
    }
    return self;
}


- (void)initializeUserInterface{
    
    
    [self addSubview:self.backView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).with.offset(5);
        make.left.equalTo(self).with.offset(0);
        make.right.equalTo(self).with.offset(0);
        make.bottom.equalTo(self).with.offset(-5);
    }];
   
    
    [self addSubview:self.articleName];
    [self.articleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).with.offset(10);
        make.left.equalTo(self).with.offset(10);
        make.right.equalTo(self).with.offset(-10);
        make.height.mas_equalTo(25);
    }];
    
//    self.articleName.sd_layout
//    .leftSpaceToView(self, 10)
//    .topSpaceToView(self, 80)
//    .heightIs(130)
//    .widthRatioToView(self, 0.4);
    
    [self addSubview:self.detailName];
    [self.detailName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.articleName.mas_bottom).with.offset(5);
        make.left.equalTo(self).with.offset(10);
        make.right.equalTo(self).with.offset(-10);
        make.height.mas_equalTo(40);
    }];
    
    [self addSubview:self.authorName];
    [self.authorName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.detailName.mas_bottom).with.offset(10);
        make.left.equalTo(self).with.offset(10);
        make.right.equalTo(self.mas_centerX).with.offset(-10);
        make.height.mas_equalTo(20);
    }];
    
    [self addSubview:self.zanButton];
    [self.zanButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.detailName.mas_bottom).with.offset(10);
        make.right.equalTo(self).with.offset(-60);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(20);
    }];
    
    [self addSubview:self.talkButton];
    [self.talkButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.detailName.mas_bottom).with.offset(10);
        make.right.equalTo(self).with.offset(-30);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(20);
    }];
}


#pragma mark -- Getters
- (UILabel *)articleName{
    if (!_articleName) {
        _articleName = [[UILabel alloc] init];
        _articleName.font = [UIFont boldSystemFontOfSize:18];
//        _articleName.backgroundColor = [UIColor orangeColor];
       
    }
    return _articleName;
}

- (UILabel *)detailName{
    if (!_detailName) {
        _detailName = [[UILabel alloc] init];
        _detailName.font = [UIFont systemFontOfSize:15];
        [_detailName setTextColor:[UIColor darkGrayColor]];
//        _detailName.backgroundColor = [UIColor orangeColor];
        _detailName.numberOfLines = 2;
        
    }
    return _detailName;
}

- (UILabel *)authorName{
    if (!_authorName) {
        _authorName = [[UILabel alloc] init];
        _authorName = [[UILabel alloc] init];
        _authorName.font = [UIFont systemFontOfSize:15];
        [_authorName setTextColor:[UIColor lightGrayColor]];
//        _authorName.backgroundColor = [UIColor orangeColor];
        
    }
    return _authorName;
}

- (UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc] init];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}


- (UIButton *)zanButton{
    if (!_zanButton) {
        _zanButton = [[UIButton alloc] init];
        [_zanButton setImage:[UIImage imageNamed:@"zan2.png"] forState:UIControlStateNormal];
        _zanButton.titleLabel.text = @"(0)";
        [_zanButton setImage:[UIImage imageNamed:@"selectedZan.png"] forState:UIControlStateSelected];
        
        _zanButton.titleLabel.textAlignment = NSTextAlignmentLeft;
        [_zanButton addTarget:self action:@selector(respondsToZanButton:) forControlEvents:UIControlEventTouchUpInside];
        //        _zanButton.backgroundColor = [UIColor blueColor];
        
    }
    return _zanButton;
}


- (UIButton *)talkButton{
    if (!_talkButton) {
        _talkButton = [[UIButton alloc] init];
        [_talkButton setImage:[UIImage imageNamed:@"评论.png"] forState:UIControlStateNormal];
        _talkButton.titleLabel.text = @"(0)";
        _talkButton.titleLabel.textAlignment = NSTextAlignmentLeft;
        //        _talkButton.backgroundColor = [UIColor blueColor];
    }
    return _talkButton;
}


- (void)respondsToZanButton:(UIButton *)sender{
    NSLog(@"谢谢你的赞");
    _zanButton.selected = !_zanButton.selected;
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
